package leetcode.code0290;

import java.util.HashSet;
import java.util.Set;

public class Solution {

	public boolean wordPattern(String pattern, String s) {
		String[] strings = s.split(" ");
		if (pattern.length() != strings.length) {
			return false;
		}
		String[] dics = new String[26];
		Set<String> set = new HashSet<>();
		char[] cs = pattern.toCharArray();
		for (int i = 0; i < cs.length; i++) {
			int cur = cs[i] - 'a';
			String str = strings[i];
			if (dics[cur] == null) {
				if (set.contains(str)) {
					return false;
				}
				set.add(str);
				dics[cur] = str;
			} else if (!dics[cur].equals(str)) {
				return false;
			}
		}
		return true;
	}
}
